import pyautogui  # 获取鼠标坐标
import pyperclip  # 操作剪贴板（比 win32clipboard 更简单）
from pynput import keyboard  # 监听键盘快捷键

def get_mouse_position():
    """返回鼠标坐标，格式为 'x,y'"""
    x, y = pyautogui.position()
    return f"{x},{y}"

def on_activate():
    """当按下 Ctrl+1 时执行"""
    coords = get_mouse_position()
    pyperclip.copy(coords)  # 复制到剪贴板
    print(f"坐标已复制: {coords}")

# 定义热键组合 Ctrl+1
hotkey = keyboard.HotKey(
    keyboard.HotKey.parse('<ctrl>+1'),
    on_activate
)

# 键盘监听回调
def on_press(key):
    hotkey.press(l.canonical(key))

def on_release(key):
    hotkey.release(l.canonical(key))

# 启动键盘监听
print("程序运行中，按 Ctrl+1 获取鼠标坐标（可重复触发）")
print("按 Esc 退出程序")

with keyboard.Listener(on_press=on_press, on_release=on_release) as l:
    l.join()